package com.springcloud_consumer.config;

import com.netflix.loadbalancer.*;
import com.myrules.MyRibbonRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @author: wu linchun
 * @time: 2021/9/16 17:36
 * @description:
 */
@Configuration
public class ConfigBean {
    //配置负载均衡实现RestTemplate
    @Bean
    @LoadBalanced  //Ribbon 配置负载均衡实现restTemplate
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    //IRule
    //RoundRobinRule：轮询
    //RandomRule：随机
    //AvailabilityFilteringRule：会过滤掉跳闸、访问故障的服务~，对剩下的进行轮询~
    //RetryRule：会先按照轮询获取服务，如果服务获取失败会在指定的时间内进行重试
//    @Bean
//    public IRule myRule() {
//        //随机切换服务
//       return new RandomRule();
////        return new RoundRobinRule();
////        return new AvailabilityFilteringRule();
////        return new RetryRule();
//       // return new MyRibbonRule();
//    }
}
